<?php
/**
 * author      :chenwenwen
 * createTime  :2020-04-12 16:21
 * description :
 */
declare(strict_types=1);

namespace app\api\controller;

use app\BaseController;
use app\common\business\sms as SmsBusiness;

class Sms extends BaseController {
    public function code(): object {
        $phoneNumber = $this->request->param('phone_number', '', 'trim');
        $data = ['phone_number' => $phoneNumber];
        try {
            validate(\app\api\validate\User::class)->scene('send_code')->check($data);
        } catch (\think\exception\ValidateException $e) {
            return show(config('status.error'), $e->getError(), []);
        }

        //调用business层数据
        if (SmsBusiness::sendCode($phoneNumber, 6)) {
            return show(config('status.success'), '发送验证码成功', []);
        }
        return show(config('status.error'), '发送验证码失败', []);
    }
}